package com.xiaoze.question.controller;

import java.util.List;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xiaoze.common.annotation.Log;
import com.xiaoze.common.core.controller.BaseController;
import com.xiaoze.common.core.domain.AjaxResult;
import com.xiaoze.common.enums.BusinessType;
import com.xiaoze.question.domain.QuestionAnswerUser;
import com.xiaoze.question.service.IQuestionAnswerUserService;
import com.xiaoze.common.utils.poi.ExcelUtil;
import com.xiaoze.common.core.page.TableDataInfo;

/**
 * 用户回答Controller
 *
 * @author 胡昊泽
 * @date 2024-08-02
 */
@RestController
@RequestMapping("/question/user" )
public class QuestionAnswerUserController extends BaseController {
    @Autowired
    private IQuestionAnswerUserService questionAnswerUserService;

    /**
     * 查询用户回答列表
     */
    @PreAuthorize("@ss.hasPermi('question:user:list')" )
    @GetMapping("/list" )
    public TableDataInfo list(QuestionAnswerUser questionAnswerUser) {
        startPage();
        List<QuestionAnswerUser> list = questionAnswerUserService.selectQuestionAnswerUserList(questionAnswerUser);
        return getDataTable(list);
    }

    /**
     * 导出用户回答列表
     */
    @PreAuthorize("@ss.hasPermi('question:user:export')" )
    @Log(title = "用户回答" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(QuestionAnswerUser questionAnswerUser) {
        List<QuestionAnswerUser> list = questionAnswerUserService.selectQuestionAnswerUserList(questionAnswerUser);
        ExcelUtil<QuestionAnswerUser> util = new ExcelUtil<QuestionAnswerUser>(QuestionAnswerUser.class);
        return util.exportExcel(list, "user" );
    }

    /**
     * 获取用户回答详细信息
     */
    @PreAuthorize("@ss.hasPermi('question:user:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(questionAnswerUserService.selectQuestionAnswerUserById(id));
    }

    /**
     * 新增用户回答
     */
    @PreAuthorize("@ss.hasPermi('question:user:add')" )
    @Log(title = "用户回答" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QuestionAnswerUser questionAnswerUser) {
        return toAjax(questionAnswerUserService.insertQuestionAnswerUser(questionAnswerUser));
    }

    /**
     * 修改用户回答
     */
    @PreAuthorize("@ss.hasPermi('question:user:edit')" )
    @Log(title = "用户回答" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QuestionAnswerUser questionAnswerUser) {
        return toAjax(questionAnswerUserService.updateQuestionAnswerUser(questionAnswerUser));
    }

    /**
     * 删除用户回答
     */
    @PreAuthorize("@ss.hasPermi('question:user:remove')" )
    @Log(title = "用户回答" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(questionAnswerUserService.deleteQuestionAnswerUserByIds(ids));
    }
}
